import { useEffect, useState } from "react";
import { Button, Form, Input, Table, Card, } from 'antd';
import TextArea from "antd/es/input/TextArea";
import FetchHelper from "../../../../../../utils/helper/fetch-helper";
import { useHistory } from "react-router-dom/cjs/react-router-dom.min";
import FxpgApi from "../../../../../../utils/apis/FxpgApi";


export default function FxpgbbglAdd() {
  const [fxpgbbglAddDynamicForms, setFxpgbbglAddDynamicForms] = useState();
  const { form } = Form.useForm();
  const history = useHistory();
 // const [jcdjcXqDatas, setJcdjcXqDatas] = useState();
  useEffect(() => {
    FxpgApi.fxpgbbglAddDynamicApi().then(datas => {
      // console.log(datas)
      setFxpgbbglAddDynamicForms(datas)
    })
  }, [])

  //完成提交
  const onFinish = (values) => {
    //console.log("values",values)
    FetchHelper.postJson(`/admin-api/ybyj/fxpg`, values).then(alert('新增成功！')).catch(err => alert("保存失败") + err)
  }
  //取消修改
  const quxiaoHandle = () => {
    history.push(`/manager/Fxpgbggl`)
  }
  return <>
    <Card className='h100 fill' style={{
      overflow: "scroll"
    }}>
      <Form method="post"
        onFinish={onFinish}
        form={form}
        className="layout-v fill">
        <header style={{
          fontSize: 20,
          fontWeight: "bold"
        }}>风险评估报告管理新增</header>
        <hr />


        <div className="InputForm" style={{
          flex: "flex",
          flexWrap: "wrap"
        }}>
          {fxpgbbglAddDynamicForms !== undefined && fxpgbbglAddDynamicForms.map(formItem => {
            let node;
            switch (formItem.type) {
              case 'Textarea':
                node = <TextArea></TextArea>;
                break;
              case 'input':
              default:
                node = <Input style={{
                  width: '90%'
                }}


                />
            }

            return <div style={{
              flexBasis: "33%",
              marginBottom: "10px"
            }}><Form.Item
              label={formItem.alias}
              name={formItem.name}
            // rules={[{
            //     required: true
            // }]}
            >{node}</Form.Item></div>
          })}
        </div>
        <div className="layout-h">
          <Button className="btn1" type="primary" htmlType="submit" >保存</Button>
          <Button onClick={quxiaoHandle} className="btn2">返回</Button>
        </div>

      </Form>
    </Card>
  </>
}